package org.cug.service.impl;

import org.cug.mapper.GraduationProjectMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.GraduateProject;
import org.cug.pojo.User;
import org.cug.service.GraduationProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GraduationProjectServiceimpl implements GraduationProjectService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private GraduationProjectMapper graduateProjectMapper;
    @Override
    public List<GraduateProject> list(Integer userId) {
        User user =userMapper.getrole(userId);
        List<Integer> ids=new ArrayList<>();
        if(user.getRole().equals("1")){
            ids.add(userId);
        }
        else if(user.getRole().equals("2")){
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<GraduateProject> graduatedesigns=graduateProjectMapper.listAll();
            return graduatedesigns;
        }
        List<GraduateProject> graduatedesigns=graduateProjectMapper.list(ids);
        return graduatedesigns;
    }

    @Override
    public void add(GraduateProject graduatedesign) {
        graduateProjectMapper.insert(graduatedesign);
    }

    @Override
    public void delete(List<Integer> ids) {
        graduateProjectMapper.delete(ids);
    }

    @Override
    public GraduateProject selectid(Integer id) {
        return graduateProjectMapper.select(id);
    }

    @Override
    public void alterbyid(GraduateProject graduatedesign) {
        graduateProjectMapper.update(graduatedesign);
    }
}
